<template>
    <input type="file" :accept="accept" @change="fileChange" ref="file">
</template>
<script>
export default{
    props:{
        accept:{
            type:String,
            default:""
        }
    },
    data(){
        return{

        }
    },
    methods:{
        open(){
            this.$refs.file.click();
        },
        fileChange(){
            let file = this.$refs.file.files[0];
			let parma = new FormData();
			parma.append("file",file)
			this.$http({
				method:'post',
				url:this.$api.uploadFile,
				data:parma
			}).then(res=>{
				if(res.data){
					// this.form.picdir = res.data;
                    this.$emit("fileChange",res.data)
					this.$refs.file.value = "";
				}else{
                    this.$message.error("上传文件失败！")
                }
			})
        }
    }
}
</script>
<style scoped>
input{
    position: fixed;
    z-index: -100;
    display: none;
}
</style>